package com.quasar.hpatient.view.adapter;

import android.text.style.ForegroundColorSpan;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.constant.ConstantManger;
import com.quasar.hpatient.model.custommodel.RemindMedicineTableItem;
import com.quasar.hpatient.utils.Spanny;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/10/26 0026
 * View:
 */

public class RemindMedicineAdapter extends BaseMultiItemQuickAdapter<RemindMedicineTableItem, BaseViewHolder> {

    public RemindMedicineAdapter(List<RemindMedicineTableItem> data) {
        super(data);
        addItemType(RemindMedicineTableItem.TAIL, R.layout.medicine_title_layout);//头布局
        addItemType(RemindMedicineTableItem.HEAD, R.layout.widget_remind_medicine);//药物头布局
        addItemType(RemindMedicineTableItem.BODY, R.layout.widget_remind_medicine);//药品布局
        addItemType(RemindMedicineTableItem.FOUR, R.layout.medication_bottom_layout);//药品布局

    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }

    @Override
    protected void convert(BaseViewHolder helper, RemindMedicineTableItem item) {
        switch (helper.getItemViewType()) {
            case RemindMedicineTableItem.BODY:
                //药品名称
                helper.setText(R.id.remind_med_name, item.name);
                //剂量
                helper.setText(R.id.remind_dose,item.specifications);
                //规格
                helper.setText(R.id.remind_specifications,item.dose);
                //状态
                Spanny spanny = new Spanny();
                if(item.stats== ConstantManger.MEDICINEDIDNOTSUIT){
                    spanny.append("未服", new ForegroundColorSpan(color(R.color.red)));
                    helper.setText(R.id.remind_stats,spanny);
                }else if(item.stats==ConstantManger.MEDICINEBORMAL){
                    spanny.append("已服", new ForegroundColorSpan(color(R.color.btcolor)));
                    helper.setText(R.id.remind_stats,spanny);
                }else if(item.stats==ConstantManger.MEDICINETIMEOUT){
                    spanny.append("超时", new ForegroundColorSpan(color(R.color.yellow1)));
                    helper.setText(R.id.remind_stats,spanny);
                }
                //服药时间
                helper.setText(R.id.remind_medicationDay,item.medicineTime);
                break;
        }
        helper.addOnClickListener(R.id.remind_med_name);//药品名称
        helper.addOnClickListener(R.id.remind_stats);//服药
        helper.addOnClickListener(R.id.tv_oneKey);//一键服药
        helper.addOnClickListener(R.id.textView4);//更多
        helper.addOnClickListener(R.id.submit);//底部一键服药
    }
}
